
import java.io.*;
import java.util.*;


public class TestWorker
{
    /** 
     * Quietly close the reader, ignoring IOExceptions.
     */
    private static void closeReader(Reader r) {
	if (r != null) {
	    try {
		r.close();
	    }
	    catch (IOException ignore) {
	    }
	}
    }


    private static void testPageParser(PageParser parser, String dataFile) 
    {
	Reader inputReader = null;
	HashMap bindingsMap = new HashMap();
	int nHits = 0;

	long t0 = System.currentTimeMillis();
	try {
	    inputReader = new BufferedReader(new FileReader(dataFile));
	    while(parser.parse(inputReader, bindingsMap)) {
		nHits += 1;
		bindingsMap.clear();
	    }
	}
	catch (Exception e) {
	    e.printStackTrace();
	}
	finally {
	    closeReader(inputReader);
	}
	long t1 = System.currentTimeMillis();

	System.out.println("Found " + nHits + " hits, elapsed Time: " + (t1 - t0) + " milliseconds");
    }


    public static void main(String[] args) 
    {
	SearchWorker worker = new LycosSearchWorker(null, "java") {
	    public Object construct() {
		TestWorker.testPageParser(getPageParser(), "data/lycospro.dump.html");
		return null;
	    }
	};
	worker.start();
    }
}

